

 //二级菜单
 
 $(function(){
    $("ul").find("li").hover(function(){
        $(this).children("ul").show();
    },function(){
        $(this).children("ul").hide();
    })
}) 


//  热卖推荐 
class List{
    constructor(){
        this.url = "http://localhost:3000/api";
        this.cont= document.querySelector(".rmtj-detail")
        this.load();
    }
    load(){
        ajax({
            url:this.url,
            data:{
                type:"getGoods"
            },
            success:res=>{
                // console.log(res);
                this.res=JSON.parse(res).msg;
                // console.log(this.res);
                this.ranner();
            }
        })
    }
    ranner(){
        let str = "";
        this.res.forEach(val=>{
            str +=` <li class="item">	       
            <p class="pic"><img src="${val.img}" alt=""></p>	       
            <p class="name"><a>${val.proName}</a></p>	        
            <p class="price" >¥<span>${val.price}</span></p>	        <p class="btn"><a class="buy">立即抢购</a></p> </li>`
        })
        this.cont.innerHTML = str;
    }
}
new List();

//商品列表
class Splist{
    constructor(){
        this.url = "http://localhost:3000/api";
        this.spbox= document.querySelector(".spbox")
        this.load();
        this.oimg=document.querySelectorAll(".spbox .sp-list img");
        this.oname=document.querySelectorAll(".spbox .item-name")
        addEvent();
       
        
    }
    addEvent(){
        this.oimg.addEventListener("click",fn1)
        function fn1(){
            location.herf="./third-Magnifier.html"
        }
        this.oname.addEventListener("click",fn2)
        function fn2(){
            location.herf="./third-Magnifier.html"
        }
    }
    load(){
        ajax({
            url:this.url,
            data:{
                type:"getGoods1"
            },
            success:res=>{
                console.log(res);
                this.res=JSON.parse(res);
                // console.log(this.res);
                this.ranner();
            }
        })
    }
    ranner(){
        let str = "";
        this.res.forEach(val=>{
            str +=`<li class="sp-list1 box" index="${val.proId}">
            <img src="${val.img}" alt="" >
            <div>
                <p class="item-price">
                    <span class="price">￥${val.price}</span>
                </p>
            </div>
            <p class="item-name"><a rel="nofollow" class="item-link" herf="./third-Magnifier.js">${val.proName}</a></p>
            <p class="item-comment-dispatching">
                <a href="" class="comment">
                    <span class="grey" style="font-size: 12px
                    ;">已有</span>
                    2910
                    <span class="grey">人评价</span>
                </a>
            </p>
            <p class="item-shop"><span class="nnamezy">自营</span></p>
            <p class="item-option">
                加入购物车
            </p>
        </li>`
        })
        this.spbox.innerHTML = str;
    }
}
// new Splist();




